<?php
class EmailModel extends BaseModel implements Model {
    function __construct() {
        parent::__construct("emails", "email_name");
        $this->addField("email_name", Model::TYPE_VARCHAR, Model::MOD_PRIMARY);
        $this->addField("subject", Model::TYPE_VARCHAR);
        $this->addField("content", Model::TYPE_VARCHAR);
    }

    public function renderAlias($record) {
        $result = $record;
        return $result;
    }

    public function saveEmailFromParams($key, $params) {
        $fldList = array(
            subject => $params[$key . "_subject"],
            content => $params[$key],
        );
        $query = QueryHelper::update("emails", $fldList, "email_name='$key'");
        Database::executeQuery($query);
    }

    public function isAuthorized($operation, $subject = "") {
        return true;
//        if (Auth::isAdmin()) { return true; }
/*
        switch ($operation) {
            case "update" :
            case "delete" :
            case "addnew" : {
                if (Auth::canChangeDrivers()) { return true; }
            }
            case "list" : {
                if (Auth::canListDrivers()) { return true; }
            }
        }
        return false;
*/
    }

    public function modifyDatabaseInput($data) {
        $result = array();
        return $result;
    }
}

?>
